/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.AA中等题.链表最大孪生和;

import java.util.LinkedList;

public class Main {
 class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

    class Solution {
        public int pairSum(ListNode head) {
            LinkedList<Integer> data=new LinkedList<>();
            while (head!=null){
                data.addLast(head.val);
                head=head.next;
            }
            int size= Integer.MIN_VALUE;
            while (!data.isEmpty()){
                int middle=data.pollFirst()+data.pollLast();
                size=Math.max(size, middle);
            }
            return size;
        }
    }
}
